(function () {
    var module = {};
    var tools = Tools();
    var mobileCode = 0;
    module.init = function () {
        tools.getUserInfo();
        module.toCheck();

        $(document).on("click", ".openAccount_open", function () {
            $('.goOpenAccount').hide();
        });
        $(document).on("click", ".openAccount_close", function () {
            $('.openAccount_close').attr('href', 'center.html')
        });
        $(document).on("click", ".oa_wcNext", function () {
            $('#member').show();
            $('.oa_wcNext').hide();
        });

        $(document).on("click", ".oa_bts", function () {
            mobileCode++;
            if (mobileCode != 1) {
                return;
            }

            if (toCheckPhone()) {
                if (toCheckBank()&&toCheckCard()) {
                    if (toCheckName()) {
                        var datas = {
                            name: $('#User_youName').val(),  //姓名
                            identity: $('#User_Name').val(),  //身份证号码
                            mobile: $('#User_mobile').val(),  //银行预留手机号
                            cardNo:$('#User_card').val() //银行卡号
                        };
                        tools.doPost(accountURL + tools.apiURL.buildOpenAccountParms, datas, module.buildOpenAccountParms);
                    }
                }
            }
        });
    };
    module.buildOpenAccountParms = function (data) {
            if(data.status==0){
                tools.formPost(data.data.actionUrl, data.data.parms);
            }else{
                $("#alertMessage").fadeIn();
                $("#message").text(data.message);
                setTimeout(function(){
                    $("#alertMessage").fadeOut();
                },2000)
            }
        
    };
    module.toCheck = function () {
        //身份校验
        $(document).on('keyup', '#User_Name', function () {
            toCheckCard();
        });
        //银行卡
        $(document).on('keyup', '#User_card', function () {
            toCheckBank();
        });
        //手机号
        $(document).on('keyup', '#User_mobile', function () {
            toCheckPhone();
        });
        //用户名
        $(document).on('keyup', '#User_youName', function () {
            toCheckName()
        });
    };
    // 验证手机号
    function isPhoneNo(phone) {
        var pattern = /^(0|86|17951)?(13[0-9]|15[012356789]|17[0-9]|18[0-9]|14[57])[0-9]{8}$/;
        return pattern.test(phone);
    }

    function toCheckPhone() {
        var tag = true;
        if ($.trim($('#User_mobile').val()).length == 0) {
            tag = false;
            mobileCode = 0;
        } else {
            if (isPhoneNo($.trim($('#User_mobile').val())) == false) {
                tag = false;
                mobileCode = 0;
            }
        }
        if (tag) {
            $('.correctMobile').removeClass('onError');
            $('.correctMobile').addClass('onRight');
        } else {
            $('.correctMobile').removeClass('onRight');
            $('.correctMobile').addClass('onError');
        }
        return tag;
    }

    //用户名
    function toCheckName(name) {
        var str = '';
        var tag = true;
        if ($.trim($('#User_youName').val()).length == 0) {
            tag = false;
            mobileCode = 0;
        }
        if (tag) {
            $('.correctName').removeClass('onError');
            $('.correctName').addClass('onRight');
        } else {
            $('.correctName').removeClass('onRight');
            $('.correctName').addClass('onError');
        }
        return tag;
    }

    // 验证身份证
    function isCardNo(card) {
        var pattern = /^([0-9]{17}[0-9X]{1})|([0-9]{15})$/;
        return pattern.test(card);
    }
    function isInd(ind) {
        var pattern =/^\d+(\.\d+)?$/;
        return pattern.test(ind);
    }

    function toCheckCard() {
        var tag = true;
        if ($.trim($('#User_Name').val()).length == 0) {
            tag = false;
            mobileCode = 0;
        } else {
            tag = isCardNo($.trim($('#User_Name').val()));
            mobileCode = 0;
        }
        if (tag) {
            $('.correctIndentity').removeClass('onError');
            $('.correctIndentity').addClass('onRight');
        } else {
            $('.correctIndentity').removeClass('onRight');
            $('.correctIndentity').addClass('onError');
        }
        return tag;
    }

    //校验银行卡
    function toCheckBank() {
        var tag = true;
        if ($.trim($('#User_card').val()).length == 0) {
            tag = false;
            mobileCode = 0;
        } else {
         tag=isInd($.trim($('#User_card').val()));
          /*  if (tools.luhmCheck($.trim($('#User_card').val())) == false) {
                tag = false;
                mobileCode = 0;
            }*/
        } 
        if (tag) {
            $('.correctCard').removeClass('onError');
            $('.correctCard').addClass('onRight');
        } else {
            $('.correctCard').removeClass('onRight');
            $('.correctCard').addClass('onError');
        }
        return tag;
    }

    module.init();
})();